package com.bristua.barcode.customer.biz;

import com.bristua.barcode.common.util.MD5Util;
import com.bristua.barcode.customer.dao.TCustomerAccountMapper;
import com.bristua.barcode.customer.model.TCustomerAccount;
import com.bristua.barcode.customer.model.condition.TCustomerAccountExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/8/25.
 */
@Service
@Transactional
public class SetCustomerBankPwdBiz {

    @Autowired
    private GetCustomerIdBiz getCustomerIdBiz;

    @Resource
    private TCustomerAccountMapper tCustomerAccountMapper;
    
    public void setCustomerBankPwd(String pwd){
        String customerId = getCustomerIdBiz.getCustomerId();
        TCustomerAccountExample tCustomerAccountExample = new TCustomerAccountExample();
        tCustomerAccountExample.createCriteria().andCustomerIdEqualTo(customerId);
        List<TCustomerAccount> tCustomerAccounts = tCustomerAccountMapper.selectByExample(tCustomerAccountExample);
        if(tCustomerAccounts!=null && tCustomerAccounts.size()>0){
            TCustomerAccount tCustomerAccount = tCustomerAccounts.get(0);
            if(StringUtils.isEmpty(tCustomerAccount.getAccountPwd())){
                TCustomerAccount updateCustomerAccount = new TCustomerAccount();
                updateCustomerAccount.setCustomerAccountId(tCustomerAccount.getCustomerAccountId());
                updateCustomerAccount.setAccountPwd(MD5Util.Bit32(pwd));
                tCustomerAccountMapper.updateByPrimaryKeySelective(updateCustomerAccount);
            }

        }

    }
}
